<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>系统公告</title>
<%@ include file="../../common_header.jsp"%>
<script type="text/javascript" src="${ctx}/js/other.js"></script>
<script type="text/javascript">
		//状态格式化
		function showStatus(value,rec,index){
			if(value == 9)
			{
				return "<font color='green'>已推送 </font>";
			}
			else if(value == 1)
			{
				return "<font color='purple'>未推送  </font>";
			}
			else if(value == 0)
			{
				return "<font color='red'>移除  </font>";
			}
		}
		//类型格式化
		function showType(value,rec,index){
    		if(value == 0)
    		{
    			return "<font color='blue'>资讯</font>";
    		}
    		else if(value == 1)
    		{
    			return "<font color='navy'>指南 </font>";
    		}
    	}
		//添加
		function append() {
			var params = {
		                winId:'win_adds_sysNotice',
		                title:'添加公告信息',
		                width:350,
		                height:300,
		                showUrl:'${ctx}/manage/sysNotice/add',
		                refresh_fun:function(){
		                	$('#dg').datagrid('uncheckAll');
		                    $('#dg').datagrid('reload');
		                }     
		        };
		        open_fun(params);
		}
		//修改
		function edit() {
			 	var id=0;
		        var name=null;
		        var row = $('#dg').datagrid('getSelected');
		    	var len = $('#dg').datagrid('getSelections').length; 
		       	if(len>1){
		       		$.messager.alert("系统提示","亲，只能选择一个进行修改哦!");
		       	}
		       	else if(len==1 && row){
		            id = row.id;
		                var params = {
		                        winId:'win_edit_sysNotice',
		                        title:'修改公告的资料',
		                        width:350,
		                        height:300,
		                        showUrl:'${ctx}/manage/sysNotice/edit?id='+id,
		                        refresh_fun:function(){
		                        	$('#dg').datagrid('uncheckAll');
		                            $('#dg').datagrid('reload');
		                        }     
		                };
		                open_fun(params);   
		        }else{
		            $.messager.alert("系统提示","亲，请选择你要修改的信息哦!");
		        }
		}
		//移除
		function removeit() {
			var ids = [];
			var rows = $('#dg').datagrid('getSelections');
			var len = $('#dg').datagrid('getSelections').length; 
			for(var i=0; i<rows.length; i++){
				ids.push(rows[i].id);
			}
		    if(!len)
		    {
		        $.messager.alert("系统提示","亲，请选择你要移除的数据哦！");
		    }else{
		        $.messager.confirm("系统提示","亲，是否要移除你选择的数据到回收站？",function(conf){
		            if(conf){
		                var url = "${ctx}/manage/sysNotice/remove?ids="+ids;
		                $.getJSON(url, function(json){
		                    if(json.success==0)
		                    {
		                    	$('#dg').datagrid('uncheckAll');
		                        $('#dg').datagrid('reload');
		                    }
		                    else
		                    {
		                        showErrMsg(json);
		                    }
		                });
		            }                                       
		        });
		    }
		}
		//删除
		function deleteit() {
			var ids = [];
			var len = $('#dg').datagrid('getSelections').length; 
			var rows = $('#dg').datagrid('getSelections');
			for(var i=0; i<rows.length; i++){
				ids.push(rows[i].id);
			}
		    if(!len)
		    {
		        $.messager.alert("系统提示","亲，请选择你要删除的数据哦！");
		    }
		    else
		    {	
		        $.messager.confirm("系统提示","亲，是否要删除你选择的数据？",function(conf){
		            if(conf)
		            {	
		                var url = "${ctx}/manage/sysNotice/delete?ids="+ids;
		                $.getJSON(url, function(json){
		                    if(json.success==0)
		                    {
		                    	$('#dg').datagrid('uncheckAll');
		                        $('#dg').datagrid('reload');
		                    }
		                    else
		                    {
		                    	$.messager.alert("删除失败",json.msg);
		                    }
		                });
		            }                                       
		        });
		    }
		}
		//查询
		function searchit() {
			$("#dg").datagrid("load", sy.serializeObject($('#formModule').form()));
		}
		//格式化日期
		function formatDate (strTime) {
		    var date = new Date(strTime);
		    return date.getFullYear()+"-"+(date.getMonth()+1)+"-"+date.getDate()+" "+date.getHours()+":"+date.getMinutes()+":"+date.getSeconds();
		}
		//鼠标悬浮时，显示文本框里面的全部内容
   	 	function formatCellTooltip(value){  
            return "<span title='" + value + "'>" + value + "</span>";  
        }
   		//右侧菜单
		function formatOper(val, row, index) {
			return '<a href="#" onclick="editone();"><input class="btn" type="button" value="修改" ></a>  <a href="#" onclick="deleteone();"><input class="btn" type="button" value="删除" ></a>  <a href="#" onclick="removeone();"><input class="btn" type="button" value="移除" ></a>';
		}
		 //以下三个函数为单个操作
        function editone(){
        	var row = $('#dg').datagrid('getSelected');
        	var id = row.id;
            var params = {
                    winId:'win_edit_sysNotice',
                    title:'修改公告的信息',
                    width:350,
                    height:300,
                    showUrl:'${ctx}/manage/sysNotice/edit?id='+id,
                    refresh_fun:function(){
                    	$('#dg').datagrid('uncheckAll');
                        $('#dg').datagrid('reload');
                    }
                    
            };
            open_fun(params);   
        } 
        function removeone(){
        	var row = $('#dg').datagrid('getSelected');
        	var id = row.id;
        	var name = row.title;
        	 $.messager.confirm("移除确认",'移除&nbsp; <span style="color:red;font-weight:bold">'+id+'-'+name+'</span> &nbsp;？',function(conf){
                 if(conf)
                 {
                     var url = "${ctx}/manage/sysNotice/remove?ids="+id;
                     $.getJSON(url, function(json){
                         if(json.success==0)
                         {
                         	$('#dg').datagrid('uncheckAll');
                             $('#dg').datagrid('reload');
                         }
                         else
                         {
                             showErrMsg(json);
                         }
                     });
                 }                                       
             });
        	
        }     
        function deleteone(){
        	var row = $('#dg').datagrid('getSelected');
        	var id = row.id;
        	var name = row.title;
        	 $.messager.confirm("删除确认",'删除&nbsp; <span style="color:red;font-weight:bold">'+id+'-'+name+'</span> &nbsp;？',function(conf){
                 if(conf)
                 {	
                     var url = "${ctx}/manage/sysNotice/delete?ids="+id;
                     $.getJSON(url, function(json){
                         if(json.success==0)
                         {
                         	$('#dg').datagrid('uncheckAll');
                             $('#dg').datagrid('reload');
                         }
                         else
                         {
                        	 showErrMsg(json);
                         }
                        
                     });
                 }                                       
             });
        }
        //获取当前用户可查看到的部门
        $(document).ready(function(){
			
			showDataInCombotree('${ctx }/manage/sysDepartment/getAllDepaetment?flag=2',$("#depId"),'${model.sysDepartment.depId}');
			$("#depId").combobox({
        		onChange: function (n,o) {
        			searchit();
        		}
        	})	
		  });
</script>
 <style type="text/css" media="screen">
.btn{
   	border-right: #63B8FF 1px solid;
  		padding-right: 2px;
   	border-top: #63B8FF 1px solid;
   	padding-left: 2px;
   	font-size: 12px;
   	FILTER: progid:DXImageTransform.Microsoft.Gradient(GradientType=0,  StartColorStr=#ffffff,  EndColorStr=#C3DAF5);
   	border-left: #63B8FF 1px solid;
   	cursor: hand;
   	color: black;
   	padding-top: 2px;
   	border-bottom: #63B8FF 1px solid;
	}
</style>
</head>
<body class="easyui-layout">
	<div data-options="region:'north',border:false" style="height: 0px; background: #F0FFF0; padding: 5px">
		<form id="formModule" method="post">
			所属单位：<select id="depId" name="sysDepartment.depId" style="width:150px" class="easyui-combotree" style="width:232px;height:23px" data-options="required:true,editable:false"></select>                                                  
                                   类型：<select id="noticeType" name="noticeType" onchange="searchit();">
                            <option value=""  >--全部--</option>
                            <option value="0">资讯</option>
                            <option value="1">指南</option>
                   </select>
                              状态：<select id="status" name="status" onchange="searchit();">
                            <option value=""  >--全部--</option>
                            <option value="9">已推送</option>
                            <option value="1">未推送</option>
                            <option value="0">移除</option>
                </select>           
    	</form>
		</div>
	<div data-options="region:'north',border:false" style="height:0px;background:#EEEEEE;padding:0px"></div>
	<div data-options="region:'center',title:''">
				<table id="dg" class="easyui-datagrid" title="系统公告" fit="true" style="width:700px;height:250px"
				data-options="rownumbers:true,singleSelect:false,url:'/manage/sysNotice/dataGrid',method:'get',toolbar:'#toolbar',fit:true,
				showFooter:false,pagination:true,idField:'ID'">
			<thead>
				<tr>
					<th data-options="field:'ck',checkbox:true">全选</th>
					<th data-options="field:'sysDepartment',width:130,align:'center',formatter:showDept">所属单位</th>
					<th data-options="field:'title',width:150,align:'center',formatter:formatCellTooltip">公告标题</th>
					<th data-options="field:'content',width:300,align:'center',formatter:formatCellTooltip">公告内容</th>
					<th data-options="field:'noticeType',width:60,align:'center',formatter:showType">类型</th>
					<th data-options="field:'status',width:60,align:'center',formatter:showStatus">状态</th>
					<th data-options="field:'pubTime',width:180,align:'center',formatter:formatDate" >发布时间</th>
					<th data-options="field:'_operate',width:180,align:'center',formatter:formatOper">操作</th>
				</tr>
			</thead>
		</table>
		<div id="toolbar" style="height: auto;background: #F0FFF0">
			${buttons }
		</div>
	</div>
</body>
</html>